package com.clusterswisdom.horn.api.tmall.action.eticket;

import com.alibaba.fastjson.JSONObject;
import com.clusterswisdom.horn.api.ioc.HornAction;
import com.clusterswisdom.horn.api.ioc.HornResponse;
import com.clusterswisdom.horn.api.ioc.api.ApiConfig;
import com.clusterswisdom.horn.api.tmall.TmallInstance;
import com.clusterswisdom.horn.api.tmall.action.AbstractTmallAction;
import com.taobao.api.response.VmarketEticketConsumeResponse;
/**
 * 电子票券消费通知(核销)
 * @author Jin_tian
 *
 */
public class GetVmarketEticketConsumeAction extends AbstractTmallAction implements HornAction {

	@Override
	public HornResponse execute(ApiConfig config, JSONObject param) throws Exception {
		VmarketEticketConsumeResponse response = (VmarketEticketConsumeResponse)TmallInstance.getInstance().executeRequest(param, "eticket", "vmarketEticketConsume");
		if(response.isSuccess()){
			JSONObject result = getResult(response);
			result.put("torderId", param.get("oid"));
			return new HornResponse(true, getResult(response));
			
		}else{
			return getUnsuccessResponse(response);
			
		}
	}
	
	private JSONObject getResult(VmarketEticketConsumeResponse response) {
		JSONObject json = new JSONObject();
		json.put("ret_code",response.getRetCode());
		json.put("item_title",response.getItemTitle());
		json.put("left_num",response.getLeftNum());
		json.put("sms_tpl",response.getSmsTpl());
		json.put("print_tpl",response.getPrintTpl());
		json.put("consume_secial_num",response.getConsumeSecialNum());
		json.put("code_left_num", response.getCodeLeftNum());
		
		return json;
	}
}
